# 选课系统

from tortoise import Model
from tortoise.fields import IntField, CharField, ForeignKeyField, ManyToManyField


# 学生
class Student(Model):
    id = IntField(pk=True)
    name = CharField(max_length=20, description="姓名")
    pwd = CharField(max_length=20, description="密码")
    sn = IntField(description="学号")
    # 一对多关系
    clas = ForeignKeyField("models.Clas", related_name="students", description="班级")
    # 多对多关系
    courses = ManyToManyField("models.Course", related_name="students", description="课程")


# 课程
class Course(Model):
    id = IntField(pk=True)
    name = CharField(max_length=20, description="课程名称")
    teacher = ForeignKeyField("models.Teacher")
    addr = CharField(max_length=20, description="教室", default="")


# 班级
class Clas(Model):
    name = CharField(max_length=20, description="班级名称")


class Teacher(Model):
    id = IntField(pk=True)
    name = CharField(max_length=20, description="姓名")
    pwd = CharField(max_length=20, description="密码")
    tno = IntField(description="工号")
